/*******************************************************************************
 * Copyright (c) 2005, 2014 springside.github.io
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 *******************************************************************************/
package com.kratos.base.service.account;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.kratos.base.entity.User;
import com.kratos.base.repository.UserDao;

/**
 * 用户管理类.
 */
@Component
@Transactional
public class AccountService {
	public static final String HASH_ALGORITHM = "SHA-1";
	public static final int HASH_INTERATIONS = 1024;
	private static final int SALT_SIZE = 8;

	private UserDao userDao;

	public void registerUser(User user) {
		// TODO: 没有对密码进行加密
		user.setPassword(user.getPlainPassword());
		user.setSalt("salt");
		user.setRoles("user");
		userDao.save(user);
	}
	
	public User findUserByLoginName(String loginName) {
		return userDao.findByLoginName(loginName);
	}

	@Autowired
	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}
	
}
